// let getRandomValue = (): string | number => {
//     let num = Math.random()
//     return num >= 0.5 ? 'abc' : 123.3
//   }
//   // 无法得知res1返回值类型
//   let res1 = getRandomValue()

 

//   console.log('res1', res1)



class Person {
    name: string = 'css'
  }
  
  class Animal {
    age: number = 12
  }
  
  let getRandomObject = (): Person | Animal => {
    let num = Math.random()
    return num >= 0.5 ? new Person() : new Animal()
  }
  
  let obj = getRandomObject()
  console.log('obj', obj )
  if (obj instanceof Person) {
    console.log(obj.name)
  } else {
    console.log(obj.age)
  }